#include "../Line.cpp"

//Some tests for the functions in the 'Line.cpp' file. This code is not pretty, but it tests stuff, so it works.

/**
*  Checks info on Line and LineGroup.
*/
void lineTest(){
    int errors = 0;
      //Goal setup
    Line l0(0, PI, 100, coordsToAddr(10,10), coordsToAddr(110,10), coordsToAddr(60,10));
    Line l1(1, PI/2, 50, coordsToAddr(10,10), coordsToAddr(10, 60), coordsToAddr(10, 35));
    Line l2(2, PI, 100, coordsToAddr(10,60), coordsToAddr(110,60), coordsToAddr(60,60));
    Line l3(3, PI/2, 50, coordsToAddr(110,10), coordsToAddr(110, 60), coordsToAddr(110, 35));
    Line lines[4] = {l0, l1, l2, l3};
    LineGroup group(lines, 1);
    
    bool idealAdj[16] = { 0,1,0,1,
                          0,0,1,0,
                          0,0,0,1,
                          0,0,0,0 };

    bool idealPerp[16] = { 0,1,0,1,
                           0,0,1,0,
                           0,0,0,1,
                           0,0,0,0 };

    bool idealPar[16] = { 0,0,1,0,
                          0,0,0,1,
                          0,0,0,0,
                          0,0,0,0 };

    bool idealAbove[16] = { 0,1,1,1,
                            0,0,1,0,
                            0,0,0,0,
                            0,0,1,0 };

    bool idealLeft[16] = { 0,0,0,1,
                           1,0,1,1,
                           0,0,0,1,
                           0,0,0,0 };
    bool success = 1;
    bool *groupAdj = group.getR_adj();
    for(int i=0; i<16; i++){
        if(groupAdj[i]!=idealAdj[i])
            success = 0;
    }
    if(!success){
        cout << "Adjs were wrong." << endl;
        errors++;
    }

    success = 1;
    bool *groupPerp = group.getR_perp();
    for(int i=0; i<16; i++){
        if(groupPerp[i]!=idealPerp[i])
            success = 0;
    }
    if(!success){
        cout << "Perps were wrong." << endl;
        errors++;
    }

    success = 1;
    bool *groupPar = group.getR_par();
    for(int i=0; i<16; i++){
        if(groupPar[i]!=idealPar[i])
            success = 0;
    }
    if(!success){
        cout << "Pars were wrong." << endl;
        errors++;
    }

    success = 1;
    bool *groupAbove = group.getR_above();
    for(int i=0; i<16; i++){
        if(groupAbove[i]!=idealAbove[i])
            success = 0;
    }
    if(!success){
        cout << "Aboves were wrong." << endl;
        errors++;
    }

    success = 1;
    bool *groupLeft = group.getR_left();
    for(int i=0; i<16; i++){
        if(groupLeft[i]!=idealLeft[i])
            success = 0;
    }
    if(!success){
        cout << "Lefts were wrong." << endl;
        errors++;
    }

    int idealMeanPoint = coordsToAddr(60, 35);
    double idealMeanOrientation = 3*PI/4;
    double idealMeanLength = 75;

    double *groupStats = group.getA_means();
    if(idealMeanPoint != (int)groupStats[0]){
        cout << "Group mean point was wrong." << endl;
        errors++;
    }
    if(idealMeanOrientation != groupStats[1]){
        cout << "Group mean orientation was wrong." << endl;
        errors++;
    }
    if(idealMeanLength != groupStats[2]){
        cout << "Group mean length was wrong: " << groupStats[2] << ", " << idealMeanLength << endl;
        errors++;
    }

    cout << "Number of errors in lineTest: " << errors << endl;
    
}


